package org.tangdao.modules.file.model.domain;

import org.tangdao.common.suports.DataEntity;
import org.tangdao.modules.file.utils.FileUploadUtils;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import lombok.Getter;
import lombok.Setter;

/**
 * @ClassName: FileUpload
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author RuYang
 * @date 2019/03/07
 * 
 */

@Setter
@Getter
@TableName("sys_file_upload")
public class FileUpload extends DataEntity<FileUpload> {

	private static final long serialVersionUID = 1L; // 序列

	@TableId
	private String id;

	private String fileId; // 文件编号

	private String fileName; // 文件名称

	private String fileType; // 文件分类（image、media、file）

	private String bizKey; // 业务主键

	private String bizType; // 业务类型

	@TableField(exist = false)
	private FileEntity fileEntity;

	public static final String TYPE_IMAGE = "image";
	public static final String TYPE_MEDIA = "media";
	public static final String TYPE_FILE = "file";

	public FileUpload() {
		super();
	}

	public FileUpload(String fileUploadId) {
		super(fileUploadId);
	}

	public String getFileUrl() {
		return FileUploadUtils.getFileUploadService().getFileUploadServiceExtend().getFileUrl(this);
	}

	public FileEntity getFileEntity() {
		if (this.fileEntity == null) {
			this.fileEntity = new FileEntity();
		}
		return this.fileEntity;
	}

	public FileUpload(FileEntity fileEntity) {
		super(null);
		this.fileEntity = fileEntity;
		this.fileId = this.getFileEntity().getFileId();
	}

}
